<%--
  User: Shengzhao Li
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>删除</title>

</head>
<body>
<div id="thing_archive_page" data-role="page" class="page">
    <div data-role="header" data-theme="f">
        <a href="${contextPath}/m/dashboard" data-icon="home" data-direction="reverse" data-transition="slide">主页</a>

        <h1>删除</h1>
        <a href="javascript:void(0);" id="confirm_delete" data-icon="delete" data-theme="b" data-transition="slidedown">删除</a>
    </div>
    <div data-role="content">
        <div class="center red" style="display: none;" id="action_info">删除成功!</div>

        <form action="archive" id="archive_form">
            <c:forEach items="${thingArchiveDto.list}" var="t">
                <label><input type="checkbox" name="guids" value="${t.guid}"/> ${t.content} </label>
            </c:forEach>
            <c:if test="${empty thingArchiveDto.list}">
                <ul data-role="listview" data-inset="true">
                    <li>
                        <div> 没有任何事情可删除.</div>
                    </li>
                </ul>
            </c:if>
        </form>
        <c:if test="${thingArchiveDto.showMore}">
            <div data-role="controlgroup" id="archive_more_div">
                <a href="javascript:void(0);" id="archive_more_link" data-role="button" class="color-b">
                    更多 (<span
                        id="page_number">${thingArchiveDto.pageNumber}</span>/${thingArchiveDto.totalPages})<img
                        id="more_loading" src="${contextPath}/images/public/load.gif" alt="loading" class="more-img"/>
                </a>
            </div>
        </c:if>
        <div class="center gray">只有 新建 的事情允许删除.</div>
    </div>
    <div data-role="footer" data-position="fixed" data-theme="d">
        <div data-role="navbar">
            <ul>
                <li>
                    <a href="../overview" data-icon="arrow-l" data-direction="reverse" data-transition="flip">返回</a>
                </li>
            </ul>
        </div>
    </div>
    <script type="text/javascript">
        $(function() {
            <c:if test="${param.result}">
            $("#action_info").fadeIn(800).delay(800).fadeOut(800);
            </c:if>

            var pageNumber = ${thingArchiveDto.pageNumber};
            var totalSize = ${thingArchiveDto.totalSize};

            $("a#archive_more_link").bind("click", function() {
                var $this = $(this).addClass("gray");
                var nextPageNumber = (++pageNumber);
                var loading = $("#more_loading").show();
                getData();
                function getData() {
                    $.ajax({
                        url:"overview/more",
                        data:{
                            pageNumber: nextPageNumber,
                            totalSize: totalSize
                        },
                        success:function(data) {
                            var listview = $("#archive_form").append($.trim(data));
                            $.mobile.pageContainer.trigger("create");
                            $this.removeClass("gray");
                            checkShowMore(listview);
                        }
                    });
                }

                function checkShowMore(listview) {
                    var addedSize = listview.find("input:checkbox").size();
                    if (addedSize == totalSize) {
                        $("#archive_more_div").hide();
                    } else {
                        loading.hide();
                    }
                    $this.find("#page_number").html(nextPageNumber);
                }
            });

            $("#confirm_delete").bind("click", function(e) {
                var data = [];
                $("#archive_form").find("input:checked").each(function() {
                    data.push("guids=" + $(this).val());
                });
                location.href = "archive_confirm?data=" + encodeURIComponent(data.join("&"));
            });
        });
    </script>
</div>
</body>
</html>